import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class createFile_and_readFile {
	public static void main(String[] args) throws IOException {
		File file= new File("c:\\testjava1/abc/newFile.txt");
		file.getParentFile().mkdirs();
		file.createNewFile();

//		File file = new File("newFile.txt");

		FileOutputStream fos = new FileOutputStream(file);
		OutputStreamWriter osw = new OutputStreamWriter(fos);
		osw.write("hello");
		osw.append("world");
		osw.flush();
		osw.close();
		
		InputStream is = new FileInputStream(file);
		InputStreamReader isr=new InputStreamReader(is);
		BufferedReader br = new BufferedReader(isr);
		int i = 0;
		while (i != -1) {
			i = br.read();
			System.out.print((char) i);
		}
		br.close();
		isr.close();
		is.close();
		file.delete();
		file.getParentFile().delete();
		file.getParentFile().getParentFile().delete();

	}

}
